package com.bayair.doctor.ui.personal;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.bayair.doctor.App;
import com.bayair.doctor.R;
import com.bayair.doctor.base.component.BaseActivity;
import com.hjq.bar.TitleBar;
import androidx.appcompat.widget.AppCompatEditText;
import butterknife.BindView;

public class TextSettingActivity extends BaseActivity {

    public static void actionStart(Bundle bundle, OnResultReturnListener listener) {
        Intent intent = new Intent(App.getContext(), TextSettingActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(TEXT_SETTING_BUNDLE, bundle);
        App.getContext().startActivity(intent);
        sOnResultReturnListener = listener;
    }

    /**
      bundle
     */
    private static final String TEXT_SETTING_BUNDLE = "text_setting_bundle";
    public static final String TEXT_SETTING_TITLE = "text_setting_title";
    public static final String TEXT_SETTING_CONTENT = "text_setting_content";
    //回调
    private static OnResultReturnListener sOnResultReturnListener;

    @BindView(R.id.title_bar)
    TitleBar mTitleBar;
    @BindView(R.id.et_ts_content)
    AppCompatEditText mEtTsContent;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_text_setting;
    }

    @Override
    public void onRightClick(View v) {
        String textInput = mEtTsContent.getText().toString();
        if (sOnResultReturnListener != null) {
            sOnResultReturnListener.onReturn(textInput);
        }
        onBackPressed();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        Bundle bundle = getIntent().getBundleExtra(TEXT_SETTING_BUNDLE);
        String title = bundle.getString(TEXT_SETTING_TITLE);
        String content = bundle.getString(TEXT_SETTING_CONTENT);
        mTitleBar.setTitle(title);
        mEtTsContent.setText(content);
    }

    @Override
    protected void initData() {

    }

    public interface OnResultReturnListener {
        void onReturn(String str);
    }

}
